package com.ruoyi.settled.controller;

import com.ruoyi.settled.domain.SettlementAgreement;
import com.ruoyi.settled.service.ISettlementAgreementService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 结算协议Controller
 * 
 * @author huangchen
 * @date 2025-01-18
 */
@RestController
@RequestMapping("/agreement/agreement")
public class SettlementAgreementController extends BaseController
{
    @Autowired
    private ISettlementAgreementService settlementAgreementService;

    /**
     * 查询结算协议列表
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreement:list')")
    @GetMapping("/list")
    public TableDataInfo list(SettlementAgreement settlementAgreement)
    {
        startPage();
        List<SettlementAgreement> list = settlementAgreementService.selectSettlementAgreementList(settlementAgreement);
        return getDataTable(list);
    }

    /**
     * 导出结算协议列表
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreement:export')")
    @Log(title = "结算协议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SettlementAgreement settlementAgreement)
    {
        List<SettlementAgreement> list = settlementAgreementService.selectSettlementAgreementList(settlementAgreement);
        ExcelUtil<SettlementAgreement> util = new ExcelUtil<SettlementAgreement>(SettlementAgreement.class);
        util.exportExcel(response, list, "结算协议数据");
    }

    /**
     * 获取结算协议详细信息
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreement:query')")
    @GetMapping(value = "/{agreementCode}")
    public AjaxResult getInfo(@PathVariable("agreementCode") String agreementCode)
    {
        return success(settlementAgreementService.selectSettlementAgreementByAgreementCode(agreementCode));
    }

    /**
     * 新增结算协议
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreement:add')")
    @Log(title = "结算协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SettlementAgreement settlementAgreement)
    {
        return toAjax(settlementAgreementService.insertSettlementAgreement(settlementAgreement));
    }

    /**
     * 修改结算协议
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreement:edit')")
    @Log(title = "结算协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SettlementAgreement settlementAgreement)
    {
        return toAjax(settlementAgreementService.updateSettlementAgreement(settlementAgreement));
    }

    /**
     * 删除结算协议
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreement:remove')")
    @Log(title = "结算协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agreementCodes}")
    public AjaxResult remove(@PathVariable String[] agreementCodes)
    {
        return toAjax(settlementAgreementService.deleteSettlementAgreementByAgreementCodes(agreementCodes));
    }


    /**
     * 根据合作方编码获取合作方详细信息
     */
    @PostMapping("/getAgreementByPartnerCode")
    public AjaxResult getAgreementByPartnerCode(@RequestBody String partnerCode){
        return success(settlementAgreementService.selectSettlementAgreementByPartnerCode(partnerCode));
    }


    /**
     * 根据合作方编码获取协议编码
     */
    @PostMapping("/getAgreementCodeByPartnerCode")
    public AjaxResult getAgreementCodeByPartnerCode(@RequestBody String partnerCode){
        return success(settlementAgreementService.selectSettlementAgreementCodeByPartnerCode(partnerCode));
    }



}
